package cm309.BookingSystem.vm;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class VenueDeleteHandler extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		int id = Integer.valueOf(req.getParameter("id"));
		try {
			Connection conn = null;
			try {
				conn = VenueDao.getConnection();
				PreparedStatement ps;
				ps = conn.prepareStatement("DELETE FROM BK_VM_VENUE WHERE ID=?");
						
				ps.setInt(1, id);
				

				int count = ps.executeUpdate();
				conn.commit();
				RequestDispatcher dispatcher = req.getRequestDispatcher("venueResult.html");
				dispatcher.forward(req, resp);
			}catch (SQLException e) {
				conn.rollback();
				e.printStackTrace();
				
			}finally {
				conn.close();
			}
			
		}catch (Exception e){
			e.printStackTrace();
		}			
	}

}
